package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/9/11 10:35
 * @apiNote
 */

public class Test01984MinimumDifference {
    public int minimumDifference(int[] nums, int k) {
        int n = nums.length;
        Arrays.sort(nums);
        int ans = Integer.MAX_VALUE;
        for(int i = 0;i+k < n-1;i++){
            ans = Math.min(ans,nums[i+k-1]-nums[i]);
        }
        return ans;
    }
}
